﻿// ==================================================
// Copyright © 2016 杭州伯庸科技 版权所有
//
// 文 件 名：FlyTogether
// 功能描述：
//
// 创建标识：Yu.Liang(俞 亮) 2018/4/10 13:07:11
//
// 修改标识：
// 修改描述：
// ==================================================

using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using Shine.Framework;
using System.Configuration;

using SuperMap.Data;
using SuperMap.Realspace;


namespace Shine.FlyManager
{
    internal class FlyTogether : BaseCommand
    {
        IApplication m_Application = null;
        SuperMap.Realspace.FlyManager fm = null;

        public FlyTogether()
        {
            base.m_caption = "连续飞行";
            base.m_name = "FlyTogether";
            base.m_toolTip = "连续飞行";
            base.m_message = "连续飞行";
            base.m_category = "FlyManager";
            base.m_enabled = false;
        }

        public override void OnCreate(object hook)
        {
            if (m_Application == null)
            {
                m_Application = hook as IApplication;
                fm = (m_Application as IFramework).SceneControl.Scene.FlyManager;
            }

            if (fm != null && fm.Routes.CurrentRoute != null)
            {
                base.m_enabled = true;
            }
        }

        public override void OnClick()
        {
            //if (string.IsNullOrEmpty((m_Application as IFramework).SelectedRoute)) return;
            //string file = Application.StartupPath + "\\飞行路线\\" + (m_Application as IFramework).SelectedRoute + ".fpf";
            //if (System.IO.File.Exists(file))
            //{
            //    SuperMap.Realspace.FlyManager fm = (m_Application as IFramework).SceneControl.Scene.FlyManager;
            //    fm.Routes.Clear();
            //    if (fm.Routes.FromFile(file))
            //    {
            //        fm.Play();
            //    }
            //}
            fm = (m_Application as IFramework).SceneControl.Scene.FlyManager;
            if (fm != null)
            {
                for (int i = 0; i < fm.Routes.Count; i++)
                {
                    fm.Play();
                }
            }            
        }

        public override int Bitmap
        {
            get
            {
                string imgFile = Application.StartupPath + "\\Images\\" + GetType().Name + ".png";

                if (System.IO.File.Exists(imgFile) == false) return 0;

                return new Bitmap(Image.FromFile(imgFile)).GetHbitmap().ToInt32();
            }
        }


        public override bool Enabled
        {
            get {
                return (m_Application as IFramework).IsSceneCtlActive; 
            }
        }
    }
}
